<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片展开</title>
    <style>
        .image-container {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            position: relative;
            width: 500px;
            height: 500px;
        }
        .image-container img {
            position: absolute;
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
            cursor: pointer;
        }
        .mask {
            position: absolute;
            left: 0;
            width: 100%;
            /* 初始从底部开始，高度为 0 */
            top: 100%;
            height: 0;
            background-color: white;
            /* 为 top 和 height 属性添加过渡效果 */
            transition: top 0.5s ease, height 0.5s ease;
            z-index: 1;
        }
    </style>
</head>
<body>
    <button id="unfold">关闭</button>
    <button id="down">展开</button>
    <div class="image-container">
        <img src="./img/GitHub头像.jpg" alt="Image 1">
        <div class="mask"></div>
    </div>
</body>
<script>
    const unfold = document.getElementById('unfold');
    const down = document.getElementById('down');
    const mask = document.querySelector('.mask');

    // 检查元素是否成功获取
    if (unfold && down && mask) {
        unfold.addEventListener('click', function () {
            // 点击展开时，蒙版从上向下消失
            mask.style.top = '0';
            mask.style.height = '100%';
        });

        down.addEventListener('click', function () {
            // 点击关闭时，蒙版由下向上遮罩
            mask.style.top = '100%';
            mask.style.height = '0';
        });
    } else {
        console.error('部分元素未成功获取，请检查 HTML 结构。');
    }
</script>
</html>